package dbs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

/**
 * Oracle 连接调用
 * 
 * @author Beanstao@gmail.com
 * @date 2013-10-15上午9:11:33
 * @version 1.0
 */
public class OracleConnection
{
	public static void main(String[] args)
	{
		try
		{
			String sql = "select value from v$parameter where name = 'processes' ";
			_Statement = getConnection().createStatement();
			ResultSet rSet = _Statement.executeQuery(sql);
			System.out.println(rSet.getInt(1));
		}
		catch (Exception e)
		{
			System.err.println("oracle数据库驱动未载入。" + e);
		}

	}

	/**
	 * 未完成的测试
	 */
	public static void noIndex()
	{
		StringBuffer sql = new StringBuffer();

		System.out.println("OracleTest.main()" + new Date());
		sql.append("begin ");
		for (int j = 0; j < 50000;)
			sql.append("insert into TEST (id,name) values(" + j++ + ",'yang');");
		sql.append("end; ");
		System.out.println("OracleTest.main()" + new Date());
		System.out.println("OracleTest.main()>>>sql:" + sql);
		System.out.println("OracleTest.main()" + new Date());
	}

	static String url = "jdbc:oracle:thin:@192.168.2.58:1521:ORCL";
	static String user = "soms520";
	static String password = "ny3Ydhy9YxQ77RAv";
	static Connection _Connection = null;
	static Statement _Statement = null;

	public static Connection getConnection()
	{
		try
		{
			Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
			_Connection = DriverManager.getConnection(url, user, password);
		}
		catch (Exception e)
		{
			System.err.println("oracle数据库驱动未载入。" + e);
		}
		System.out.println("连接成功");

		return _Connection;
	}
}
